package io;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;

/**
 *
 * @author Mariano Zapata
 */
public class Cola<E> {
    
    private List<E> cola;
    private Semaphore semaforo;
    
    public Cola()
    {
        semaforo= new Semaphore(0, true);
        cola= new ArrayList<E>();
    }
    
    public void encolar(E o)
    {
        cola.add(o);
        semaforo.release();
    }
    
    public E desencolar() throws InterruptedException
    {
        semaforo.acquire();
        return cola.remove(0);
    }
}
